#!/usr/bin/python
# -*- encoding: utf-8

import urllib, urllib2

def tryGetTextFromUrl(url, encoding=None):
    text = None
    
    try:
        request = urllib2.Request(url)
        request.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        
        response = urllib2.urlopen(request)
        
        try:
            text = response.read()
            
            if encoding is not None:
                text = text.decode(encoding)
        finally:
            response.close()
            
    except:
        pass
    
    return text